<%--
    入社审批界面
    Author: scm
    Date: 2023-12-12
    Version: 1.0
--%>
<%--
    需要的数据
    membershipApplicationList 根据搜索框输入的申请人username（可能不完整），返回查找到的所有符合的入社申请
    如果搜索框没输入，则返回所有本社团的入社申请

    currentPage 就是页面传入的参数page（具体见本页面“分页展示部分”）
    totalPage 总数/每页展示的数（我这里设置的10）

    传入的数据
    keyword 搜索的关键词（见搜索部分）
    page 当前页面号（见分页展示部分）
    id 审核通过/不通过的membershipApplicationID（见审核按钮部分）
--%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page session="true" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="<c:url value="/resources/css/bootstrap.css"/>">
    <link rel="stylesheet" href="<c:url value="/resources/css/systemStyle.css"/>">
    <title>校园社团管理系统</title>
</head>
<body>
<!-- 顶部导航栏 -->
<jsp:include page="./header.jsp" />
<div class="content container">
    <!-- 搜索框  -->
    <nav class="navbar bg-body-tertiary">
        <div class="container-fluid">
            <div class="fs-4 fw-bolder">申请列表</div>
            <form class="d-flex" role="search" action="<c:url value="../clubAdministrator/membershipApplications" />" method="get">
                <input type="search" class="form-control me-2" placeholder="输入申请人用户名" name="keyword" aria-label="Search">
                <button class="btn btn-outline-success text-nowrap" type="submit" id="search">搜索</button>
            </form>
        </div>
    </nav>
    <!-- membershipApplication信息列表  -->
    <div class="list">
        <c:if test="${not empty membershipApplicationList}">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th scope="col" class="text-center">ID</th>
                    <th scope="col">申请人</th>
                    <th scope="col">学院</th>
                    <th scope="col">申请时间</th>
                    <th scope="col">状态</th>
                    <th scope="col" colspan="2" class="text-center">操作</th>
                </tr>
                </thead>
                <c:forEach items="${membershipApplicationList}" var="membershipApplication" varStatus="loop" begin="${(currentPage-1)*10}" end="${currentPage*10-1}">
                    <tr>
                        <th class="text-center">${membershipApplication.membershipApplicationID}</th>
                        <td>${membershipApplication.applicant.username}</td>
                        <td>${membershipApplication.applicant.college}</td>
                        <td><fmt:formatDate value="${membershipApplication.applicationTime}" pattern="yyyy/MM/dd HH:mm" /></td>
                        <td>
                            <c:choose>
                                <c:when test="${membershipApplication.status == 0}">
                                    待审
                                </c:when>
                                <c:when test="${membershipApplication.status == -1}">
                                    拒绝
                                </c:when>
                                <c:when test="${membershipApplication.status == 1}">
                                    通过
                                </c:when>
                            </c:choose>
                        </td>
                        <c:choose>
                            <c:when test="${membershipApplication.status == 0}">
                                <td class="text-center">
                                    <!-- 审核通过按钮 -->
                                    <form action="<c:url value="../clubAdministrator/membershipApplications/pass" />" method="post">
                                        <input type="hidden" name="id" value="${membershipApplication.membershipApplicationID}" />
                                        <input type="submit" class="btn btn-outline-success" value="通过" />
                                    </form>
                                </td>
                                <td class="text-center">
                                    <!-- 审核不通过按钮 -->
                                    <form action="<c:url value="../clubAdministrator/membershipApplications/rejected" />" method="post">
                                        <input type="hidden" name="id" value="${membershipApplication.membershipApplicationID}" />
                                        <input type="submit" class="btn btn-outline-danger" value="拒绝" />
                                    </form>
                                </td>
                            </c:when>
                            <c:when test="${membershipApplication.status != 0}">
                                    <td colspan="2" class="text-center">
                                        <input type="submit" class="btn btn-outline-success" value="已审核" disabled/>
                                    </td>
                            </c:when>
                        </c:choose>

                    </tr>
                </c:forEach>
            </table>
            <!-- 分页展示 -->
            <div class="d-flex justify-content-evenly">
                <c:if test="${currentPage > 1}">
                    <div class="pre-page">
                        <a href="<c:url value="../clubAdministrator/membershipApplications?page=${currentPage - 1}" />" class="btn btn-outline-secondary">&lt; 上一页</a>
                    </div>
                </c:if>
                <c:if test="${currentPage <= 1}">
                    <div class="pre-page">
                        <a href="<c:url value="../clubAdministrator/membershipApplications?page=${currentPage - 1}" />" class="btn btn-outline-secondary disabled">&lt; 上一页</a>
                    </div>
                </c:if>
                <p class="currentPage ">第 ${currentPage} 页</p>
                <c:if test="${currentPage < totalPage}">
                    <div class="next-page">
                        <a href="<c:url value="../clubAdministrator/membershipApplications?page=${currentPage + 1}" />" class="btn btn-outline-secondary">下一页 &gt;</a>
                    </div>
                </c:if>
                <c:if test="${currentPage >= totalPage}">
                    <div class="next-page">
                        <a href="<c:url value="../clubAdministrator/membershipApplications?page=${currentPage + 1}" />" class="btn btn-outline-secondary disabled">下一页 &gt;</a>
                    </div>
                </c:if>
            </div>
        </c:if>
        <c:if test="${empty membershipApplicationList}">
            <p class="text-center text-danger">没有申请</p>
        </c:if>
    </div>
</div>
<jsp:include page="./footer.jsp" />
<script src="<c:url value="/resources/js/bootstrap.bundle.js" />"></script>
</body>
</html>